#include "slideshowdialog.h"
#include "ui_slideshowdialog.h"
#include "picanimationwid.h"
#include "prelistwid.h"
#include "protreewidget.h"

SlideShowDialog::SlideShowDialog(QWidget *parent,QTreeWidgetItem* first_item,QTreeWidgetItem* last_item) :
    QDialog(parent),
    ui(new Ui::SlideShowDialog),
    _first_item(first_item),
    _last_item(last_item)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);
    ui->slidePreBtn->SetIcons(":/icon/previous.png",":/icon/previous_hover.png",":/icon/previous_press.png");
    ui->slideNextBtn->SetIcons(":/icon/next.png",":/icon/next_hover.png",":/icon/next_press.png");
    ui->closeBtn->SetIcons(":/icon/closeshow.png",":/icon/closeshow_hover.png",":/icon/closeshow_press.png");

    ui->playBtn->SetIcons(":/icon/play.png",":/icon/play_hover.png",":/icon/play_press.png"
                          ,":/icon/pause.png",":/icon/pause_hover.png",":/icon/pause_press.png");

    connect(ui->closeBtn,&QPushButton::clicked,this,&SlideShowDialog::close);//设置轮播图的关闭逻辑
    connect(ui->slideNextBtn,&QPushButton::clicked,this,&SlideShowDialog::SlotSlideNext);//设置轮播图的切换下一张逻辑
    connect(ui->slidePreBtn,&QPushButton::clicked,this,&SlideShowDialog::SlotSlidePre);//设置轮播图的切换上一张逻辑

    auto* prelistWid = dynamic_cast<PreListWid*>(ui->listWidget);
    connect(ui->picAnimation,&PicAnimationWid::SigPreList,prelistWid,&PreListWid::SlotUpPreList);
    connect(ui->picAnimation,&PicAnimationWid::SigSelectItem,prelistWid,&PreListWid::SlotUpSelect);

    //实现点击缩略图然后切换图片的逻辑
    connect(prelistWid,&PreListWid::SigUpSelectShow,ui->picAnimation,&PicAnimationWid::SlotUpSelectShow);
    //实现播放和暂停的逻辑
    connect(ui->playBtn,&PicStateButton::clicked,ui->picAnimation,&PicAnimationWid::SlotStartOrStop);
    //当开启轮播图演示的时候通知界面将按钮按照正确方式展示
    connect(ui->picAnimation,&PicAnimationWid::SigStart,ui->playBtn,&PicStateButton::SlotStart);
    connect(ui->picAnimation,&PicAnimationWid::SigStop,ui->playBtn,&PicStateButton::SlotStop);

    //设置音乐播放逻辑
    auto* protree_widget = dynamic_cast<ProTreeWidget*>(parent);
    connect(ui->picAnimation,&PicAnimationWid::SigStartMusic,protree_widget,&ProTreeWidget::SlotStartMusic);
    connect(ui->picAnimation,&PicAnimationWid::SigStopMusic,protree_widget,&ProTreeWidget::SlotStopMusic);

    ui->picAnimation->SetPixmap(_first_item);
    ui->picAnimation->Start();
}

SlideShowDialog::~SlideShowDialog()
{
    delete ui;
}

void SlideShowDialog::SlotSlideNext()
{
    ui->picAnimation->SlideNext();
}

void SlideShowDialog::SlotSlidePre()
{
    ui->picAnimation->SlidePre();
}

